<?php

namespace SYSTEM;

class Autoloader {
    
    private function __construct() {
        
    }

    public static function registerAutoloader() {
        spl_autoload_register(array('SYSTEM\Autoloader', 'load'));
    }

    public static function load($nsname) {
        $path = self::normalizeFolders($nsname);
        
        if($path) {
            include $path;
        } else {
            //TODO...
            die("<hr>Cannot load class ".$nsname."<hr>");
        }
    }
    
    private static function normalizeFolders(&$nsname) {
        $str = "";
        $arr = explode("\\", $nsname);
        
        for($i = 0; $i < count($arr) - 1; $i++) {
            $str .= strtolower($arr[$i]).DIRECTORY_SEPARATOR;
        }
        
        return realpath($str.ucfirst($arr[count($arr) - 1]).".php");
    }
}